package com.kanshu.ksgb.fastread.doudou.common.business.ad.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.kanshu.ksgb.fastread.doudou.app.Xutils;
import com.kanshu.ksgb.fastread.doudou.app.constants.Constants;

/**
 * 作者    wcy
 * 时间    2018/12/6 13:12
 * 文件    doudou
 * 描述
 */
public class AdExploreTimeUtils {

    private static SharedPreferences sSharedPreferences;

    private static void initIfNeed() {
        if (sSharedPreferences != null) {
            return;
        }
        sSharedPreferences = Xutils.getContext().getSharedPreferences(Constants.SP_READ_NAME, Context.MODE_PRIVATE);
    }

    /**
     * 设置广告曝光次数
     * @param pos
     * @param type
     * @param time
     */
    public static void saveAdExposureTime(String pos, String type, int time) {
        initIfNeed();
        sSharedPreferences.edit().putInt(spliceToString(pos, type), time).apply();
    }

    /**
     * 获取广告曝光次数
     * @param pos
     * @param type
     * @return
     */
    public static int getAdExposureTime(String pos, String type) {
        initIfNeed();
        return sSharedPreferences.getInt(spliceToString(pos, type), 0);
    }

    private static String spliceToString(String pos, String type) {
        StringBuilder sb;
        sb = new StringBuilder();
        sb.append("exposure").append(pos).append(type);
        return sb.toString();
    }
}
